(function() {
    fetch('http://chst.vip:1234/api/getbrandtitle').then(body => body.json()).then(res => {
        let result = res.result;
        let titleName = '';
        result.forEach(async item => {
            let demo = await getDate(item.brandTitleId)
            titleName += `
            <h3 date-categoryId="${item.categoryId}">${item.brandTitle} <i>▼</i></h3>
            <ul class="rankingContent">
            ${demo}
            </ul>
            `
            $('.ranking').html(titleName);
        });
        async function getDate(index) {
            index -= 0;
            let dateStr = '';
            await fetch('http://chst.vip:1234/api/getbrand?brandtitleid=' + index).then(body => body.json()).then(res => {
                let result = res.result;
                result.forEach((item, index) => {
                    dateStr += `
                    <li date-brandTitleId="${item.brandTitleId}" date-categoryId="${item.categoryId}">
                        <a href="#">
                            <div class="head">
                                <span>${index+1}</span>
                                <h4>${item.brandName}</h4>
                            </div>
                            <p>
                                30天全网销售:${item.brandInfo}
                            </p>
                        </a>
                        
                    </li>
                `
                });
            })
            return dateStr
        }
    });
    //点击事件
    $('.ranking').on('click', 'h3', function() {
        $(this).next().stop().slideToggle(200);
        $(this).next().on('click', 'li', function() {
            let brandtitleid = $(this).attr('date-brandTitleId');
            let title = $(this).find('h4').text()
            location.href = '../html/11-1.html?title=' + title + '&brandtitleid=' + brandtitleid;
        })
    });
})()